/**
 * 
 */
package com.java.test.datacenter.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.java.test.activity.dto.ActivityManageInfo;
import com.java.test.audit.dto.RemitPaymentInfo;
import com.java.test.controller.BaseController;
import com.java.test.datacenter.dto.HaviorAllData;
import com.java.test.datacenter.dto.HaviorData;
import com.java.test.datacenter.dto.HomeAccountInfo;
import com.java.test.datacenter.dto.HomePageItem;
import com.java.test.datacenter.dto.PayInmentInfo;
import com.java.test.datacenter.dto.PaymentInfo;
import com.java.test.datacenter.dto.SumAccountInfo;
import com.java.test.datacenter.dto.SumAccountList;
import com.java.test.datacenter.service.DataManageService;
import com.java.test.user.dto.BehaviorInfo;
import com.java.test.user.dto.DepositInfo;
import com.java.test.user.dto.ReflectInfo;
import com.java.test.user.dto.RunWaterInfo;
import com.java.test.util.HttpErrorCode;
import com.java.test.util.JsonResult;
import com.java.test.util.PageInfo;

/**
 * @author 数据中心
 *
 */
@RestController
@RequestMapping("/datamanage")
public class DataManagementController extends BaseController {

	@Autowired
	private DataManageService dataManageService;

	// 账目汇总
	@RequestMapping("/homepageList")
	public JsonResult homepageList(@RequestBody HomePageItem info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			HomeAccountInfo infos = dataManageService.selecthomeData(info);
			if (infos == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(infos);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	// 账目汇总
	@RequestMapping("/sunaccountList")
	public JsonResult depositList(@RequestBody SumAccountInfo info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			SumAccountList infos = dataManageService.dealAcountData(info.getStartTime(), info.getEndTime());
			if (infos == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(infos);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	// ---- 出款統計

	@RequestMapping("/chukunList")
	public JsonResult chukunList(@RequestBody PageInfo<PaymentInfo> page) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			PageInfo<PaymentInfo> info = dataManageService.selectpaymentInfoList(page);
			if (info == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(info);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	@RequestMapping("/currentCount")
	public JsonResult currentCount(@RequestBody PaymentInfo infos) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			Double info = dataManageService.curToDaySumAmount(infos);
			if (info == null) {
				info = Double.valueOf(0);
			}
			js.setData(info);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	@RequestMapping("/detailByuId")
	public JsonResult detailByuId(@RequestBody PaymentInfo info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			List<RemitPaymentInfo> list = dataManageService.selectremitInfoById(info);
			if (list == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(list);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	// =================================入款统计
	/**
	 * 
	 * 入款列表
	 * 
	 * @param page
	 * @return
	 */
	@RequestMapping("/rukunList")
	public JsonResult rukunList(@RequestBody PageInfo<PayInmentInfo> page) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			PageInfo<PayInmentInfo> info = dataManageService.selectpaymentInInfoList(page);
			if (info == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(info);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 当天入款总数
	 * 
	 * @return
	 */
	@RequestMapping("/rukuncurrentCount")
	public JsonResult rukuncurrentCount(@RequestBody PayInmentInfo infos) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			Double info = dataManageService.selectcurtoDayInamount(infos);
			if (info == null) {
				info = Double.valueOf(0);
			}
			js.setData(info);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 入款明细
	 * 
	 * @param infos
	 * @return
	 */
	@RequestMapping("/rukunBybankAccount")
	public JsonResult rukunBybankAccount(@RequestBody PayInmentInfo info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			List<DepositInfo> list = dataManageService.selectdinfoBybankaccount(info.getBankAcount(),
					info.getStartTime(), info.getEndTime());
			if (list == null || list.size() <= 0) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(list);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/********** ==============交易流水============== **************/
	/**
	 * 交易流水列表
	 * 
	 * @param page
	 * @return
	 */
	@RequestMapping("/allrunwaterList")
	public JsonResult allrunwaterList(@RequestBody PageInfo<RunWaterInfo> page) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			JSONObject info = dataManageService.selectallRunwaterpage(page);
			if (info == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(info);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 当前交易流水统计
	 * 
	 * @return
	 */
	@RequestMapping("/curallrunwaterInfo")
	public JsonResult curallrunwaterInfo(@RequestBody ActivityManageInfo infos) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			SumAccountList info = dataManageService.selectRunwaterCount(infos);
			if (info == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(info);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/********* =======提现记录表========== *************/
	/**
	 * 提现记录列表
	 * 
	 * @param page
	 * @return
	 */
	@RequestMapping("/amountReflectList")
	public JsonResult amountReflectList(@RequestBody PageInfo<ReflectInfo> page) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			PageInfo<ReflectInfo> info = dataManageService.selecAmoutReflect(page);
			if (info == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(info);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 存款记录列表
	 * 
	 * @param page
	 * @return
	 */
	@RequestMapping("/amountdepositList")
	public JsonResult amountdepositList(@RequestBody PageInfo<DepositInfo> page) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			PageInfo<DepositInfo> info = dataManageService.selecAmoutDeposit(page);
			if (info == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(info);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/******** ==============行为统计=============== *********/

	/**
	 * 行为记录列表
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/curhaviorList")
	public JsonResult curAllList(@RequestBody BehaviorInfo info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			JSONObject infos = dataManageService.selectHaviorcount(info.getStartTime(), info.getEndTime());
			if (infos == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(infos);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/***
	 * 行为 -- 汇总数据
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/curhaviorone")
	public JsonResult curhaviorone(@RequestBody BehaviorInfo info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			List<HaviorData> list = dataManageService.selectHavior(info.getStartTime(), info.getEndTime(),
					info.getBehaviorType());
			js.setData(list);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 行为记录需要导出的excel数据
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/curhaviorexcel")
	public JsonResult curhaviorexcel(@RequestBody BehaviorInfo info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			HaviorAllData infos = dataManageService.selectHaviorexcel(info.getStartTime(), info.getEndTime());
			if (infos == null) {
				js.setCode(HttpErrorCode.PARAMERROR.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(infos);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}

		return js;
	}

}
